home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
comm
/
superv22.zip
/
SUPERCOM.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1987-01-23
|
14KB
|
474 lines
{ SUPERCOM
Buffered communications support library for Turbo Pascal
(C) Copyright 1986, 1987 by Doctor Debug/ Steel City Software
These routines are meant to be called by user programs. The
SUPERCOM.COM Interrupt 14 driver must have been installed to
use any of these routines. Use of these routines without proper
installation of SUPER.COM will produce unpredictable results.
The integers InError and OutError will always contain the error
conditions after every receive or transmit. The bits of these
values are defined as:
Bit 7 (128) Timeout
Bit 3 (8) Framing Error
Bit 2 (4) Parity Error
Bit 1 (2) Overrun Error
If the value of InError[port] is 0, then you can be sure that the
last character was received without error.
The value or Port is always 1 or 2 (which gets translated to 0 or
1 - I love IBM).
Procedure InitPort(port,Baud,Parity,data_bits,stop_bits)
Baud: integer 300-9600
Parity: char, E(ven),O(dd),N(one)
Data_bits: integer, 7 or 8
Stop_bits: integer, 1 or 2
This routine initializes the communications port
to the parameters specified and activates SUPERCOM
for that port. All of the following functions will
use the port specified here.
Function PortStatus(port)
This function returns the line status and modem control
status of the comm port specified. The bits returned are
defined as:
Bit 15 (negative) Time out (no device connected)
Bit 14 (16384) Transmission shift register empty
Bit 13 (8192) Transmission holding register empty
Bit 12 (4096) Break detect
Bit 11 (2048) Framing error
Bit 10 (1024) Parity error
Bit 9 (512) Overrun error
Bit 8 (256) Data ready
Bit 7 (128) Received line signal detect
Bit 6 (64) Ring indicator
Bit 5 (32) Data set ready
Bit 4 (16) Clear to send
Bit 3 (8) Delta receive line signal detect
Bit 2 (4) Trailing edge ring detector
Bit 1 (2) Delta data set ready
Bit 0 (1) Delta clear to send
Procedure XmitCh(ch)
This Procedure sends the character in ch out the port
specified.
Procedure XmitBlk(string)
This procedure sends the entire string out the comm port.
Procedure XmitLn(string)
This is identical to XmitBlk, but adds a CR/LF to the
end of the block.
Procedure RecCh(ch)
This procedure waits until a character is available over
the comm line and then returns it in ch. If the system times
out ch will contain a nul (Ascii 0).
Procedure RecLn(string)
This is the equivalent of ReadLn over the comm port.
Be sure to check the InError variable to make sure the
operation did not time out (no CR was received.)
Procedure RecBlk(number,String)
The number of characters specified by number will be
placed into the string. Be sure to check the InError
variable to assure that the operation did not time out
before sufficient characters were received.
Procedure GrabCh(ch)
If a character is waiting in the receive buffer it will
be returned in ch otherwise ch will contain a nul character.
Procedure PeekBuff(ch)
Identical to GrabCh but the character is not removed
from the buffer.
Procedure ClearBuff
Empties the receive buffer
Procedure ClosePort
Closes the comm port and deactivates SUPERCOMM until the
next InitPort.
Function Rlen
Returns the number of characters currently available in the
receive buffer.
Function SuperComPresent
Returns True if Supercom loaded, false otherwise
Procedure KillPort;
Same as ClosePort, but SuperCom will have to be reloaded
in order to use any of the functions. SUPER is removed
totally from the interrupt chain.
Procedure ChangePort(Port);
A call to this procedure changes the SUPERCOM port
to the one specified.
*************************************************************************
GLOBAL VARIABLES
*************************************************************************
}
Type
_Register_Set = Record case Integer of
1: (AX,BX,CX,DX,BP,DI,SE,DS,ES,Flags: Integer);
2: (AL,AH,BL,BH,CL,CH,DL,DH: Byte);
End;
(* NOTE: Make LSTRING whatever type string you want. For strings greater
that 255 you will have to make this an array of characters, and adjust
the other routines accordingly. The first version of these routines
used a 1024 byte monster, but using a 255 byte string will make your
application much more manageable *)
LString = String[255];
_Parity = (None,Even,Odd);
Var
_Regs: _Register_Set;
InError,OutError: Byte;
UsePort: Integer;
{***********************************************************************
InitPort
***********************************************************************}
Procedure InitPort(Port,Baud: integer;Par: _parity;D_bits,S_bits: integer);
Var
Parameter: integer;
Begin
Case Baud of
110: Baud := 0;
150: Baud := 1;
300: Baud := 2;
600: Baud := 3;
1200: Baud := 4;
2400: Baud := 5;
4800: Baud := 6;
Else Baud := 7; {default to 9600}
End;
If S_bits=2 then S_bits := 1
else S_bits := 0; {default 1 stop bit}
If D_bits=7 then D_bits := 2
else D_bits := 3; {default 8 data bits}
Parameter := (Baud shl 5) + (S_bits shl 2) + D_bits;
Case Par of
Odd: Parameter := Parameter + 8;
Even: Parameter := Parameter + 24;
Else; {default no parity}
End;
With _Regs do
Begin
AH := 12; {Activate SuperCom}
AL := Parameter; {set-up parameters}
DX := Port-1; {port to use}
Intr($14,_Regs); {perform function}
End;
UsePort := Port-1; {Save for later use}
End; {InitPort}
{*************************************************************************
Changeport
**************************************************************************}
Procedure ChangePort(p:integer);
Begin
With _Regs do
Begin
DX := p-1;
AH := 9;
Intr($14,_Regs);
End;
End;
{**************************************************************************
ClearBuff
**************************************************************************}
Procedure ClearBuff;
Begin
With _Regs do
Begin
DX := UsePort;
AH := 4;
Intr($14,_Regs);
End;
End;
{***************************************************************************
ClosePort
***************************************************************************}
Procedure ClosePort;
Begin
WIth _Regs do
Begin
DX := UsePort;
AH := 13;
Intr($14,_Regs);
End;
End;
{***************************************************************************
Port Status
***************************************************************************}
Function PortStatus:integer;
Begin
With _Regs do
Begin
AH := 3; {Status Request}
DX := UsePort;
Intr($14,_Regs);
PortStatus := AX;